package com.itheima.test02;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test04 {
    public static void main(String[] args) {
        HashMap<String, ArrayList<String>> hm = new HashMap<>();
        ArrayList<String> sgyy = new ArrayList<>();
        ArrayList<String> shz = new ArrayList<>();
        ArrayList<String> xyj = new ArrayList<>();
        sgyy.add("赵云");
        sgyy.add("马超");
        shz.add("李逵");
        shz.add("燕青");
        xyj.add("孙悟空");
        xyj.add("猪八戒");
        hm.put("三国演义", sgyy);
        hm.put("水浒传", shz);
        hm.put("西游记", xyj);
/*        Set<String> strings = hm.keySet();
        for (String string : strings) {
            //遍历键的集合,拿到每个键string
//            hm.get(string)拿到每个ArrayList
            for (String s : hm.get(string)) {
                //遍历每个键对应的值
                System.out.println(string+","+s);
            }
            System.out.println();
        }*/

        Set<Map.Entry<String, ArrayList<String>>> pairs = hm.entrySet();
        //获取键值对集合,遍历键值对
        for (Map.Entry<String, ArrayList<String>> pair : pairs) {
            //获取每个键值对 pairs
            String key = pair.getKey();
            ArrayList<String> value = pair.getValue();
            for (String s : value) {
                System.out.println(key+","+s);
            }
            System.out.println();

        }


    }
}
